public
class TaskExtController {

public List<Task> taskList {get; set;}
public List<SelectOption> searchFilterList = new List<SelectOption>();
public String selSearchFilter {get;set;}
String userId;
public TaskExtController(ApexPages.StandardController controller) {

taskList = new List<Task>();

userId = UserInfo.getUserid();

taskList = [
select ActivityDate,CreatedDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed'];

}

public void searchTasks() {
 if(selSearchFilter == 'Overdue') {
        taskList = [
            select ActivityDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' and ActivityDate < :system.today()];
    }
    if(selSearchFilter == 'Today') {
        taskList = [
            select ActivityDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' and ActivityDate =: system.today()];
    }
    if(selSearchFilter == 'Today + Overdue') {
        taskList = [
            select ActivityDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' and ActivityDate <= :system.today() ];
    }
    if(selSearchFilter == 'Tomorrow') {
        taskList = [
            select ActivityDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' and ActivityDate =: system.today()+1];
    }
    if(selSearchFilter == 'Next 7 Days') {
        taskList = [
            select ActivityDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' and (ActivityDate >= :system.today() and ActivityDate <=:system.today()+7)];
    }
    
  if(selSearchFilter == 'Next 7 Days + Overdue') {
        taskList = [
            select ActivityDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' and  ActivityDate <=:system.today()+7];
    }
     if(selSearchFilter == 'This Month') {
        List<Task> listTask = new List<Task>();
        listTask = [
            select ActivityDate,CreatedDate, Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' and ActivityDate != null];
        taskList = new List<Task>();
        for (Task tk : listTask){
            if (tk.ActivityDate.month() == System.today().month()){
                tasklist.add(tk);
               
            }
        }
            
    }
    
    if(selSearchFilter == 'All Open') {
        taskList = [
            select ActivityDate,Status, Priority, Subject, State__c, WhoId, Who.Name, WhatId, What.Name, Owner.name, ShortComments__c from Task where OwnerId = :userId and Status !=: 'Completed' ];
    }
     
    
}

public List<SelectOption> getSearchFilterList() {
   
    searchFilterList.add(new SelectOption('Overdue','Overdue'));
     searchFilterList.add(new SelectOption('Today','Today'));
    searchFilterList.add(new SelectOption('Today + Overdue','Today + Overdue'));
    searchFilterList.add(new SelectOption('Tomorrow','Tomorrow'));
    searchFilterList.add(new SelectOption('Next 7 Days','Next 7 Days'));  
      searchFilterList.add(new SelectOption('Next 7 Days + Overdue','Next 7 Days + Overdue'));
     searchFilterList.add(new SelectOption('This Month','This Month'));
     searchFilterList.add(new SelectOption('All Open','All Open')); 
    return searchFilterList;
}

/**

* This method is used to navigate to the new task creation page.

*/

public PageReference newTask() {

return new PageReference('/00T/e');

}
}